import requests
from fake_useragent import UserAgent
from com.hua.spider.yzm_util import get_code


def get_image():
    img_url = 'http://www.yundama.com/index/captcha'
    response = requests.get(img_url, headers=headers)
    with open('yzm.jpg', 'wb') as f:
        f.write(response.content)
    code = get_code('yzm.jpg')
    return code

def do_login(code):
    login_url='http://www.yundama.com/index/login?'
    from_data={
        "username": "ssh2020",
        "password": "ssh2020",
        "utype": "1",
        "vcode": code
    }
    response=session.get(login_url,headers=headers,params=from_data)
    print(response.text)

if __name__ == '__main__':
    # session保证同一次会话
    session = requests.Sessioin()
    index_url = 'http://www.yundama.com/'
    headers = {
        "User-Agent": UserAgent().random
    }
    response = session.get(index_url, headers=headers)
    code=get_image()
    if code=="":
        print("看不清")
    do_login(code)

img_url = 'http://www.yundama.com/index/captcha'

# username: zhangsan
# password: aaaaaaaaaa
# utype: 1
# vcode: yaga
